package com.frame.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

public class MyBatisUtil {
    private static SqlSessionFactory sqlSessionFactory;

    public static SqlSession openSqlSession(){
        if(sqlSessionFactory==null){
            try {
                InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("config.xml");
                sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return sqlSessionFactory.openSession();
    }
}
